/*    
    LogParser - Log File Parser Unit Tests
    Copyright (C) 2007  Alois Kraus
  
    This source code is published under the Microsoft Permissive License (Ms-PL)
    http://www.microsoft.com/resources/sharedsource/licensingbasics/permissivelicense.mspx
*/

using System;
using System.Collections.Generic;
using System.Text;
using System.Globalization;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Logging;
using System.Diagnostics;
using EntLibContrib.Logging.Parser;

#if !NUNIT
using Microsoft.VisualStudio.TestTools.UnitTesting;
#else
using NUnit.Framework;
using TestClass = NUnit.Framework.TestFixtureAttribute;
using TestInitialize = NUnit.Framework.SetUpAttribute;
using TestCleanup = NUnit.Framework.TearDownAttribute;
using TestMethod = NUnit.Framework.TestAttribute;
#endif

namespace EntLibContrib.Logging.UnitTests.Parser
{
    [TestClass]
    public class TokenizerTests
    {
        const string TraceLog = "trace.log";
        const string RollingLog = "rolling.log";

        const int RUNS = 1;

        [TestMethod]
        #if !NUNIT
        [DeploymentItem("loggingtest.config")]
        [DeploymentItem("trace.log")]
        #endif
        public void ParseRollingFile()
        {
            FilteredLogFileReader reader = new FilteredLogFileReader(TraceLog,
                ConfigReaderTests.SampleConfigFile,
                new TimeStampParser(new CultureInfo("de-DE")));

            Filter filter = new Filter();
            filter.StopTime = DateTime.MinValue;

            Stopwatch watch = Stopwatch.StartNew();
            for (int i = 0; i < RUNS; i++)
            {
                foreach (LogEntry entry in reader.ParseLogFile(filter))
                {
                    Console.WriteLine("Got message: {0}, Date: {1}", entry.Message, entry.TimeStamp);
                }
            }
            watch.Stop();
            int TotalMessages = RUNS * TestDataGenerator.TotalMessages;

            Console.WriteLine("Parsed {0} messages in {1:F1}s, Frequency: {2:F1} Messages/s",
                TotalMessages, watch.ElapsedMilliseconds / 1000.0f, TotalMessages / (watch.ElapsedMilliseconds / 1000.0f));
        }
    }
}
